#include "QQEntryController.h"

QQEntryController::QQEntryController(QWidget* parent)
	: QObject(parent)
{
	mEntryView = new QQEntryView(parent);
	qq_network->subscribeNetwork(this, QString("entry"), QString("doReadyRead"));
	connect(mEntryView, &QQEntryView::entryInfoSubmit, this, &QQEntryController::doEntryInfoSubmit);
	connect(mEntryView, &QQEntryView::registerInfoSubmit, this, &QQEntryController::doRegisterInfoSubmit);
	connect(mEntryView, &QQEntryView::findPasswordInfoSubmit, this, &QQEntryController::doFindPasswordInfoSubmit);
}

QQEntryController::~QQEntryController()
{
	qq_network->unsubscribeNetwork(QString("entry"));
}

void QQEntryController::doReadyRead(const QJsonObject& data)
{
}

void QQEntryController::showView()
{
	mEntryView->show();
}

void QQEntryController::closeView()
{
	mEntryView->close();
}

void QQEntryController::doEntryInfoSubmit(const QString& account, const QString& password)
{
	if (!qq_settings->checkCurrentAccountEntryState(account))
	{
		qq_network->entry(account, password);
	}
	else
	{
		mEntryView->showMessageBar(tr("Account is already logged in your computer"));
	}
}

void QQEntryController::doRegisterInfoSubmit(const QString& nickname, const QString& phone, const QString& password)
{
	qq_network->registerAccount(nickname, phone, password);
}

void QQEntryController::doFindPasswordInfoSubmit(const QString& account, const QString& phone)
{
	qq_network->findPassword(account, phone);
}